//
//  RemGoodsCell.m
//  com.modada.new
//
//  Created by ferver7 on 2019/4/15.
//  Copyright © 2019 ferver7. All rights reserved.
//

#import "RemGoodsCell.h"

@implementation RemGoodsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selfCollectionView.delegate = self;
    self.selfCollectionView.dataSource = self;
}
-(void)setDataList:(NSArray *)dataList
{
    _dataList = dataList;
    [self.selfCollectionView reloadData];
}
#pragma mark -
#pragma mark - **************** collectionViewDelegate

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * itemCell= mGetCollectionViewCell(@"itemCell", indexPath);
    UIImageView * logoImage = mViewByTag(itemCell.contentView, 100, UIImageView);
    NSDictionary * infoDic = self.dataList[indexPath.row];
    [logoImage sd_setImageWithURL:[NSURL URLWithString:infoDic[@"thumbnail"]] placeholderImage:mImageByName(@"")];
    UILabel * textLabel = mViewByTag(itemCell.contentView, 101, UILabel);
    textLabel.text = [NSString stringWithFormat:@"%@¥%@",infoDic[@"name"],infoDic[@"lowerPrice"]];
    return itemCell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((mScreenWidth-40)/3,(mScreenWidth-40)/3+40);
    
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
   NSDictionary * infoDic = self.dataList[indexPath.row];
    if (self.returnGoodsDetail) {
        self.returnGoodsDetail(infoDic[@"gid"]);
    }
}
//这个是两行cell之间的间距（上下行cell的间距）
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}
//两个cell之间的间距（同一行的cell的间距）
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 10, 5, 10);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
